<?php
/*
 * Author :pandiam
 */
session_start();

if (!isset($_SESSION['uid']) || $_SESSION['uid'] == -1) {
    UI_registerError('msg_warning', "You are not logged in.");
    header('Location: login.php');
}

require_once ('../bl/bl.php');
require_once ('include/functions.php');

if ( isset($_GET['id']) )
{
    if ( !ctype_digit((string)$_GET['id']) ) {
        UI_registerError('msg_error', "Invalid category request");
        header("location: index.php");
        exit(0);
    }
    $catid = $_GET['id'];
}
else
{
    UI_registerError('msg_warning', "You haven't selected a category to insert entries to!");
    header("location: index.php");
    exit(0);
}

$entityName = $_POST['entityName'];
$attrNum = $_POST['attrNum'];
$attrVals = Array();


for ( $i = 0 ; $i < $attrNum ; $i++ )
    $attrVals[$i] = $_POST['attr'.$i];

if ( ($res = BL_insertEntity($catid, $entityName, $attrVals) ) < 0 ) {
    BL_registerError($res);
    BL_flusherrors();
}
else
    UI_registerError('msg_success', "Entity inserted successfully");

header("location: insertEntity.php?id=".$catid);
exit(0);
?>